package com.doit.day05

import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}

object _03_集合的其他api {
  def main(args: Array[String]): Unit = {
    val ints6: Array[Int] = Array(1, 2, 3, 4)
    ints6(0)= 10
    println(ints6.mkString(","))

    //可变数组
    val ints: ArrayBuffer[Int] = new ArrayBuffer[Int]()
    //添加元素
    ints.append(1, 2, 3, 4, 5, 6)
    println(ints) //1,2,3,4,5,6
    //删除元素
    ints.remove(2, 3)
    println(ints) //ArrayBuffer(1, 2, 6)

    ints.update(0, 10)
    println(ints) //10  2   6

    val i: Int = ints.apply(0)
    println(i)


    //集合
    //不了变集合
    val ints1: List[Int] = List(1, 2, 3, 4)
    val head: Int = ints1.head
    val tail: List[Int] = ints1.tail
    val last: Int = ints1.last
    /*
    1
    List(2, 3, 4)
    4
     */
    println(head)
    println(tail)
    println(last)



    //list集合中的元素不能够改变
    val i1: Int = ints1(0)
    val ints3: List[Int] = ints1.::(10)
    //Nil 空集合
    val ints4: List[Int] = ints1 ::: 2 :: 3 :: 4 :: Nil
    //
    val ints5: List[Int] = Nil.::(4).::(3).::(2).::(1)
    /**/
    println(ints4)
    println(ints5)


    //不可变的set集合
    val ints7: Set[Int] = Set(1, 2, 3, 4, 5,1,2,3,4)
    println(ints7)
    println(ints7.apply(1))//判断元素存在不存在
    println(ints7.apply(10))


    //可变的set
    val set: mutable.Set[Int] = mutable.Set()
    set.add(1)
    set.add(2)
    set.add(3)
    set.add(4)
    set.add(5)
    set.add(6)
    set.add(7)
    set.add(8)
    val ints2: mutable.Set[Int] = set.drop(2)//删除元素的个数
    println(ints2)//Set(3, 4)  Set(2, 6, 3, 7, 4, 8)
    println(set)//Set(1, 2, 3, 4)
    set.remove(1)//Set(2, 3, 4)
    println(set)


    //不可变的map
    Map((1,"zss"),(2,"lss"))
    Map(1 -> "zss",2 -> "lss")

/*    val map: mutable.Map[Int, String] = mutable.Map[Int, String]
    map.put(1,"zss")
    val maybeString: Option[String] = map.remove(1)
    if(maybeString.isDefined){
      val value: String = maybeString.get
      println(value)
    }*/










    //
//    val ints2: ListBuffer[Int] = new ListBuffer[Int]


  }
}
